import {defineStore} from 'pinia'

const useUserStore = defineStore("user", {
  persist: true,
  state: () => ({   
    name:'',
    avatar:'',
    roles:[],   
    permissions:[],
    token:'',
    userId:'',
    userInfo:{},
  }),
    actions: {
        setUserInfo(userInfo) {
            this.userInfo = userInfo
        },
        setUserId(userId) {
            this.userId = userId
        },
        setToken(token) {
            this.token = token
        },
        setName(name) {
            this.name = name
        },
        setAvatar(avatar) {
            this.avatar = avatar
        },
        setRoles(roles) {
            this.roles = roles
        },
        setPermissions(permissions) {
            this.permissions = permissions
        }
    },
    getters: {
        getUserInfo: (state) => state.userInfo, // 获取用户信息
        getToken: (state) => state.token, // 获取token
        getName: (state) => state.name, // 获取用户名
        getAvatar: (state) => state.avatar, // 获取用户头像
        getRoles: (state) => state.roles, // 获取用户角色
        getPermissions: (state) => state.permissions, // 获取用户权限
        getUserId: (state) => state.userId, // 获取用户ID
    },
});

export default useUserStore;